<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('抽奖奖品列表')" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<form id="lottery-prize-form">
				<input type="hidden" name="lotteryId" id="lotteryId" th:value="${lotteryId}"/>
			</form>
			<div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" id="addLotteryPrize">
	                <i class="fa fa-plus"></i> 新增
	            </a>
	        </div>
	        
	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table-lottery-prize"></table>
			</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
		var editFlag = [[${@permission.hasPermi('biz:lottery:edit')}]];
		var removeFlag = [[${@permission.hasPermi('biz:lottery:remove')}]];
		var prefix = ctx + "biz/lotteryPrize";


		$(function() {
		    var options = {
				id: "bootstrap-table-lottery-prize",
		        url: prefix + "/list",
				showSearch: false,
				showRefresh: false,
				showToggle: false,
				showColumns: false,
				pagination: false,
		        createUrl: prefix + "/add/" + $("#lotteryId").val(),
		        updateUrl: prefix + "/edit/{id}",
		        removeUrl: prefix + "/remove",
		        exportUrl: prefix + "/export",
		        sortName: "crteTime",
		        modalName: "奖品",
		        columns: [
		        /*{
		            field: 'lotteryId',
		            title: '抽奖活动ID'
		        },*/
		        {
		            field: 'lotteryPrizeTitle',
		            title: '奖项名称',
		            sortable: true
		        },
		        {
		            field: 'lotteryPrizeName',
		            title: '奖品名称',
		            sortable: true
		        },
		        {
		            field: 'prizeCnt',
		            title: '奖品数量',
		            sortable: true
		        },
				{
					field: 'prizeRate',
					title: '中奖概率',
					sortable: true,
					formatter: function(value, row, index) {
						return '万分之【' + row.prizeRate + '】'
					}
				},
		        {
		            field: 'prizeImgBase64String',
		            title: '奖品图片',
		            sortable: false,
					formatter: function(value, row, index) {
						return $.table.imageView(row.prizeImgBase64String);
					}
		        },
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
						var actions = [];
						actions.push('<a class="btn btn-success btn-xs edit-lotteryPrize' + editFlag + '" href="javascript:void(0)" lotteryPrizeId="' + row.lotteryPrizeId + '"><i class="fa fa-edit"></i>编辑</a> ');
						// actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="lotteryPrize(\'' + row.lotteryId + '\')"><i class="fa fa-edit"></i>奖品维护</a> ');
						actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.lotteryPrizeId + '\')"><i class="fa fa-remove"></i>删除</a> ');
						return actions.join('');
		            }
		        }]
		    };
		    $.table.init(options);

		    $("#addLotteryPrize").click(function () {
				var url = prefix + '/add/' + $("#lotteryId").val();
				// $.modal.open("添加奖品", url, '800', '550', callback);
				layer.open({
					type: 2,
					area: [ '800px', '550px'],
					fix: false,
					//不固定
					maxmin: true,
					shade: 0.3,
					title: "添加奖品",
					content: url,
					btn: ['确定', '关闭'],
					// 弹层外区域关闭
					shadeClose: true,
					yes: function(index, layero) {
						var iframeWin = layero.find('iframe')[0];
						iframeWin.contentWindow.submitHandler(index, layero);
						$.table.refresh();
					},
					cancel: function(index) {
						$.table.refresh();
					},
					success: function () {
						$(':focus').blur();
					}
				});
			});

		    $(document).on('click', '.edit-lotteryPrize', function () {
				var url = prefix + '/edit/' + $(this).attr("lotteryPrizeId");
				layer.open({
					type: 2,
					area: [ '800px', '550px'],
					fix: false,
					//不固定
					maxmin: true,
					shade: 0.3,
					title: "修改奖品",
					content: url,
					btn: ['确定', '关闭'],
					// 弹层外区域关闭
					shadeClose: true,
					yes: function(index, layero) {
						var iframeWin = layero.find('iframe')[0];
						iframeWin.contentWindow.submitHandler(index, layero);
						$.table.refresh();
					},
					cancel: function(index) {
						$.table.refresh();
					},
					success: function () {
						$(':focus').blur();
					}
				});
			});
		});
	</script>
</body>
</html>